package com.kavysoft.prueba;

import java.util.ArrayList;

import javax.xml.datatype.Duration;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class ListAdapter extends ArrayAdapter<ItemList> {
	private Context mContext;
    int layoutResourceId;
    ArrayList<ItemList> data = new ArrayList<ItemList>();
    MainActivity main;
    
    
	public ListAdapter(Context context, int layoutResourceId, ArrayList<ItemList> data, MainActivity main) {
		super(context, layoutResourceId, data);
		
		this.layoutResourceId = layoutResourceId;
		this.mContext = context;
		this.data = data;
		this.main = main;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View row = convertView;
		RecordHolderL holder = null;

		if (row == null) {
			LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
			row = inflater.inflate(layoutResourceId, parent, false);

			holder = new RecordHolderL();
			holder.txtTitle = (TextView) row.findViewById(R.id.txtTitle);
			holder.txtSubTitle = (TextView) row.findViewById(R.id.txtSubtitle);
			holder.gridview = (GridView) row.findViewById(R.id.gridview);
			row.setTag(holder);
		} else {
			holder = (RecordHolderL) row.getTag();
		}

		ItemList item = data.get(position);
		holder.txtTitle.setText(item.getTitle());
		holder.txtSubTitle.setText(item.getSubTitle());
		
		ImageAdapter customGridAdapter;
		customGridAdapter = new ImageAdapter(mContext, R.layout.row_grid,item.gridArray,main);
		holder.gridview.setAdapter(customGridAdapter);
		
		return row;
	}
	
	static class RecordHolderL {
		TextView txtTitle;
		TextView txtSubTitle;
		GridView gridview;

	}

	
}
